<%-- 
    Document   : agregarFuncion
    Created on : 22-dic-2011, 22:34:37
    Author     : Administrador
--%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Agregar funcion</title>
    </head>
    <body>
        <div id="bodydiv">
            <span style="color: #0395CC; margin-top: 20px; font-size: 20pt; font-family: Arial;"><b>Agregar funcion</b></span>
            <hr />
            <br />
            <form action="agregarFuncion" id="form">
                <jsp:useBean id="peli" class="javabeans.JBPelicula" scope="session"/>
                <div style="float: right">
                    <b style="font-size: 15px">Pelicula &nbsp;&nbsp;&nbsp;</b><jsp:getProperty name="peli" property="nombre"/>
                </div>
                <br />
                <br />
                <br />
                <c:if test="${not empty peli.listaFunciones}">
                    <a href="#" id="linkVerFunciones">Ver funciones</a>
                    <div id="verFunciones" style="display: none">
                        <table border="1">
                            <tr>
                                <th style="width: 100px"><b>Cine</b></th>
                                <th style="width: 100px"><b>Sala</b></th>
                                <th style="width: 150px"><b>Fecha</b></th>
                                <th style="width: 100px"><b>Duracion</b></th>
                                <th style="width: 100px"><b>Capacidad</b></th>
                            </tr>
                            <c:forEach var="funcion" items="${peli.listaFunciones}">
                                <tr>
                                    <td>${funcion.cine.nombre}</td>
                                    <td>${funcion.sala.numero}</td>
                                    <td><fmt:formatDate value="${funcion.fecha}" dateStyle="medium" pattern="dd/MM/yyyy HH:mm"></fmt:formatDate>  </td>
                                    <td>${funcion.duracion}</td>
                                    <td>${funcion.capacidad}</td>
                                </tr>
                            </c:forEach>
                        </table>
                    </div>
                    <br />
                    <br />
                    <br />
                </c:if>
                <table>
                    <tr>
                        <td></td>
                        <td style="width: 120px">Cines</td>
                        <td>
                            <select id="cbcines" name="cbcines" style="width: 150px; padding: 4px">
                                <c:choose>
                                    <c:when test="${not empty sessionScope.cineSeleccionado}">
                                        <option value="${cineSeleccionado.id}">${cineSeleccionado.nombre}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option> - Seleccionar - </option>
                                        <c:forEach var="cine" items="${sessionScope.cines}">
                                            <option value="${cine.id}">${cine.nombre}</option>
                                        </c:forEach>
                                    </c:otherwise>
                                </c:choose>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td >Salas</td>
                        <td>
                            <select name="cbsalas" style="width: 150px; padding: 4px">
                                <c:if test="${empty sessionScope.cineSeleccionado}">
                                    <c:remove var="salas" scope="session"/>
                                </c:if>
                                <option> - Seleccionar - </option>
                                <c:forEach var="sala" items="${sessionScope.salas}">
                                    <option value="${sala.id}">${sala.numero}</option>
                                </c:forEach>
                                <c:remove var="cineSeleccionado" scope="session"/>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>Fecha</td>
                        <td><input type="text" name="fecha" id="fecha" value="" style="width: 150px; padding: 3px"  class="required dateFormat"/></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>Horario</td>
                        <td>
                            <input type="text" name="hora" style="width: 30px; padding: 2px" maxlength="2" class="required number"/>:<input type="text" name="minutos" style="width: 30px; padding: 2px" maxlength="2" class="required number"/>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>Duracion (min)</td>
                        <td><input type="text" name="duracion" style="width: 30px; padding: 3px" maxlength="3" class="required number" /></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td>&nbsp
                            <c:if test="${not empty requestScope.error}">
                                <font color="red">${requestScope.error}</font>
                                <c:remove scope="request" var="error" /> 
                            </c:if>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td><input type="submit" value="Agregar" style="width: 150px; padding: 4px"/></td>
                    </tr>
                </table>
            </form>
        </div>

        <jsp:include page="index.jsp" />
        <script type="text/javascript">
            $(document).ready(function(){
                
                //Se carga el combo de salas deacuerdo al cine seleccionado
                $("#cbcines").change(function(){
                    location.href = "cineSeleccionado?idCine=" + $("#cbcines").val();
                }); 
                
                $("#fecha").datepicker({ dateFormat: 'dd/mm/yy' });
            
                $("#form").validate();
                
                //Muestra las funciones
                $("#linkVerFunciones").click(function(){
                    $("#verFunciones").slideToggle();
                    e.preventDefault();
                });
            })
        </script>

    </body>
</html>

